﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using NLite.Net;

namespace NLite.Security
{
    /// <summary>
    /// 定义用户对象的基本功能
    /// </summary>
    /// <typeparam name="TUser">用户数据</typeparam>
    public interface IPrincipal<TUser> : IPrincipal where TUser : IPrincipal
    {
        /// <summary>
        /// 实现了IPrincipal接口的用户数据对象
        /// </summary>
        TUser User { get; }
    }

    /// <summary>
    /// 权限服务接口
    /// </summary>
    public interface IPermissionService
    {
        /// <summary>
        /// 判读user是否拥有当前请求的权限
        /// </summary>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        bool HasPermission(IPrincipal user, IDictionary<string,object> request);
    }

    /// <summary>
    /// 授权异常
    /// </summary>
    public class AuthorizationException : Exception
    {
        /// <summary>
        /// 构造授权异常
        /// </summary>
        /// <param name="message"></param>
        public AuthorizationException(string message)
            : base(message)
        {
        }
    }
}
